package com.wan37.common.xml;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * XML文件解析工具
 *
 * @author : luoyong
 * @date : 2020-05-27 14:49
 **/
public final class XMLUtils {
    private static final Logger logger = LoggerFactory.getLogger(XMLUtils.class);

    private XMLUtils() {

    }

    public static Element parseXmlFile(String path) {
        try {
            String configFilePath = XMLUtils.class.getClassLoader().getResource(path).getPath();
            logger.info("配置文件路径: ", configFilePath);
            SAXReader saxReader = new SAXReader();
            Document document = saxReader.read(new File(configFilePath));
            Element root = document.getRootElement();
            return root;
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return null;
    }
}
